package com.koron.css2.newProjectCenter.impl.query;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.query.PjQueryStockBean;
import com.koron.css2.newProjectCenter.mapper.PjQueryStockMapper;
import com.koron.css2.newProjectCenter.vo.query.PjQueryStockVo;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 施工情况查询入口
 */
public class PjQueryStock implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        PjQueryStockBean bean = JsonUtils.objectToPojo(req.getData(), PjQueryStockBean.class);
        PjQueryStockMapper mapper = factory.getMapper(PjQueryStockMapper.class);

        PageHelper.startPage(bean.getPage(), bean.getPageCount());
        List<PjQueryStockVo> list = mapper.getList(bean);
        PageInfo<PjQueryStockVo> pageInfo = new PageInfo<>(list);
        MessageBean result = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
        result.setData(pageInfo);
        return result;
    }
}
